package com.zxbit.flash.presenter;

import com.zxbit.flash.BuildConfig;
import com.zxbit.flash.base.BasePresenter;
import com.zxbit.flash.common.Constant;
import com.zxbit.flash.common.UserInfo;
import com.zxbit.flash.mvpview.OrderListMvpView;
import com.zxbit.flash.network.CustomConsumer;
import com.zxbit.flash.network.ParamsFactory;
import com.zxbit.flash.response.BorrowingResponse;

import java.util.HashMap;
import java.util.Map;

import io.reactivex.functions.Consumer;

public class OrderListPresenter extends BasePresenter {
    private OrderListMvpView mvpView;

    public OrderListPresenter(OrderListMvpView mvpView) {
        this.mvpView = mvpView;
    }

    /**
     * 分页查询订单状态
     * @param mCurrentPage
     */
    public void getOrderList(int mCurrentPage) {
        Map<String, Object> formMap = new HashMap<>();
        // 每页10条
        formMap.put("limit", Constant.LIMIT);
        formMap.put("page", String.valueOf(mCurrentPage));
        toSubScribe(req.getOrderPageList(BuildConfig.channel, UserInfo.getToken(), ParamsFactory
                .getCommonParams(formMap)), new CustomConsumer<BorrowingResponse>() {
            @Override
            public void call(BorrowingResponse borrowingResponse) {
                mvpView.onGetDataNext(borrowingResponse);
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                mvpView.onGetDataError(throwable);
            }
        });
    }
}
